library(DeclareDesign)
library(rdss)
library(tidyverse)
library(scales)
library(ggdag)
library(ggraph)
library(ggforce)
library(ggtext)

source("code/utilities/make_dag_df.R")

dag <- dagify(Y ~ D + U,
              D ~ Z + U)
nodes <-
  tibble(
    name = c("Z", "D", "U", "Y"),
    label = c("Z", "D", "U", "Y"),
    annotation = c(
      "**Exogenous variable**<br>Instrument",
      "**Endogenous variable**<br>Treatment",
      "**Unknown heterogeneity**",
      "**Outcome**"
    ),
    x = c(1, 3, 5, 5),
    y = c(1.5, 1.5, 3.5, 1.5), 
    nudge_direction = c("S", "S", "N", "S"),
    data_strategy = "unmanipulated",
    answer_strategy = "uncontrolled"
  )
ggdd_df <- make_dag_df(dag, nodes)
g <- base_dag_plot %+% ggdd_df

g

ggsave("figures/figure_16.7.pdf", g, width = 6.5, height = 4)
ggsave("figures/figure_16.7.svg", g, width = 6.5, height = 4)
